<template>
  <div class="zzz">
    <filterPanel filterName="GLawRegulationListFilter" filterTitle="" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="GLawRegulationListTable" :tableLoading="loading" tableTitle="" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
      <zy-button @click="add" type="primary">新增法律法规</zy-button>
      <zy-button @click="exportExcel">导出列表</zy-button>
    </tablePanel>
  </div>
</template>

<script>
	import {mapGetters} from "vuex";

	export default {
		name: "GLawRegulationList",
		props: {},
		data() {
			return {
				currentPath: '/article_list',
				filterData: [
					{
						title: '标题',
						name: 'keywords',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '颁布单位',
						name: 'publish_unit',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布人',
						name: 'user_name',
						type: 'input',
						value: '',
						isShow: true,
						isSelected: true
					},
					{
						title: '颁布时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
					{
						title: '发布时间',
						name: 'create_time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
					{
						title: '最后修改时间',
						name: 'modify_time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					},
				],
				form: {
					keywords: '',
					publish_unit: '',
					user_name: '',
					create_time: [],
					modify_time: [],
					page_start: 1,
					page_size: 10
				},
				loading: false,
				tableList: [
					{
						title: '标题',
						width: 120,
						name: 'title',
						isShow: true,
						isSelected: true
					},
					{
						title: '颁布单位',
						width: 150,
						name: 'publish_unit',
						isShow: true,
						isSelected: true
					},
					{
						title: '颁布时间',
						width: 200,
						name: 'modify_time_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布人',
						width: 120,
						name: 'user_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '所属组织',
						width: 120,
						name: 'publish_unit',
						isShow: true,
						isSelected: true
					},
					{
						title: '发布时间',
						width: 200,
						name: 'create_time_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '最近修改时间',
						width: 200,
						name: 'modify_time_desc',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 200,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '详情'
							},
							{
								type: 'edit',
								name: '编辑'
							},
							{
								type: 'delete',
								name: '删除',
								btnType: 'danger'
							},
						],
						isSelected: true
					}
				],
				tableData: [],
				total: 0,
				download_url: ''
			};
		},
		computed: {
			postData() {
				let data = {
					keywords: this.form.keywords,
					publish_unit: this.form.publish_unit,
					user_name: this.form.user_name,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.create_time && this.form.create_time.length > 0) {
					data.create_time_start = this.form.time[0] / 1000;
					data.create_time_end = this.form.time[1] / 1000;
				}
				if (this.form.modify_time && this.form.modify_time.length > 0) {
					data.create_time_start = this.form.time[0] / 1000;
					data.create_time_end = this.form.time[1] / 1000;
				}
				return data;
			},
			...mapGetters(['authority']),
			isAdd() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].i;
			},
			isLook() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].q;
			},
			isEdit() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].m;
			},
			isDel() {
				return this.authority[this.currentPath] && this.authority[this.currentPath].d;
			},
		},
		watch: {},
		components: {},
		methods: {
			//导出
			exportExcel() {
				this.$import_excal(this.download_url || "");
			},
			// 新增
			add() {
				this.$toRoutePath({
					path: "/article_list/article_Detail",
					edit: true,
					query: {type: 'add'}
				});
			},
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.$axios.post(this.$api.admin_lawList, {...this.postData}).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.create_time_desc = this.$Timestamp(item.create_time)
							item.modify_time_desc = this.$Timestamp(item.modify_time)
							item.detail = this.isLook;
							item.edit = this.isEdit;
							item.delete = this.isDel;
							return item;
						});
						this.download_url = data.download_url || ''
						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0
						this.tableData = [];
					}
				}).catch(ret => {
					this.$message.error(ret.msg || '服务繁忙，请稍后再试');
				});
			},
			tableClick(data, type) {
				let {article_id} = data
				switch (type) {
					case 'detail':
					case 'edit':
						this.toLook(article_id, type)
						break;
					case 'delete':
						this.deleted(article_id)
						break;
				}
			},
			toLook(article_id, type) {
				this.$toRoutePath({
					path: "/article_list/article_Detail",
					edit: true,
					query: {article_id, type}
				});
			},
			// 删除
			deleted(article_id) {
				this.$confirm("此操作将删除该文章, 是否继续?", "提示", {
					confirmButtonText: "确定",
					cancelButtonText: "取消",
					type: "warning",
					customClass: 'message',
				}).then(() => {
					this.$axios.post(this.$api.admin_delArticle, {article_id}).then(res => {
						let {code, msg} = res;
						if (code == 200) {
							this.$message.success("删除成功!");
							this.getData();
						} else {
							this.tableList = [];
							this.$message.error(msg);
						}
					})
				}).catch(() => {
					this.$message("已取消删除");
				});
			},
		},
		mounted() {
			this.getData()
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/government/infoInteractionManage/lawRegulationList/index.less">

</style>
